<?php
	$OFFLINE = false;	
	$applicationName = $_GET['applicationName'];
	if (file_exists($applicationName.".xml")) { 
		$OFFLINE = true;
	}
	
	if ($OFFLINE == true) {		
		$xmlfile = $applicationName.".xml";
		$xmlinfoS = simplexml_load_file($xmlfile);
/*		
<root>
	<list>
		<Applicationconstant>
		<ApplicationInsanceId>24454</ApplicationInsanceId>
		<Name>basepath</Name>
		<Value>http://127.0.0.1:80/genericframe/aaa</Value>
		<Id>16</Id>
		</Applicationconstant>
	</list>
</root>
*/		
		$path ="/genericframe/applicationconstant";	
		$xpathActionResult = $xmlinfoS->xpath($path);

		$xmlm = new XmlWriter();
		$xmlm->openMemory();	
		
		while(list( , $node) = each($xpathActionResult)) {
		
			$xmlm->startElement('Applicationconstant');
			
			$xmlm->startElement('ApplicationInsanceId');$xmlm->text($node->applicationInsanceId);$xmlm->endElement();
			$xmlm->startElement('Name');$xmlm->text($node->name);$xmlm->endElement();
			$xmlm->startElement('Value');$xmlm->text($node->value);$xmlm->endElement();
			$xmlm->startElement('Id');$xmlm->text($node->id);$xmlm->endElement();
				
			$xmlm->endElement();			
		}	
		$allConstants = $xmlm->outputMemory(true);
	} else {
		include_once("dbFactory.php");
		$doc = new DOMDocument();
		
		$applicationName = $_GET['applicationName'];

		$allConstants = "";
		$sqlInsance = "select * from applicationinstance where applicationName = '".$applicationName."'";
		$instanceResult = &$conn->Execute($sqlInsance); 
		$applicationId = '';
		if (!$instanceResult->EOF) {
			$applicationId = $instanceResult->fields['id'];		
			
			$sql = "select * from applicationconstant where applicationInsanceId = ".$applicationId;

			$constantlist = &$conn->Execute($sql); 
			
			$xmlm = new XmlWriter();
			$xmlm->openMemory();	

			while (!$constantlist->EOF) {
			    $xmlm->startElement('Applicationconstant');
				
				$xmlm->startElement('ApplicationInsanceId');$xmlm->text($constantlist->fields['applicationInsanceId']);$xmlm->endElement();
				$xmlm->startElement('Name');$xmlm->text($constantlist->fields['name']);$xmlm->endElement();
				$xmlm->startElement('Value');$xmlm->text($constantlist->fields['value']);$xmlm->endElement();
				$xmlm->startElement('Id');$xmlm->text($constantlist->fields['id']);$xmlm->endElement();
					
				$xmlm->endElement();
				$constantlist->MoveNext();
			}
			$allConstants = $xmlm->outputMemory(true);

			$constantlist->Close(); # optional
			$conn->Close(); # optional
		}
	}
?>
<root>
	<list><?=$allConstants ?></list>
</root>
